<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>二维码管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function(){
			$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					var proviceId=$("#proviceId").val();
					var cityId=$("#cityId").val();
					var name=$("#name").val();
					var activeId=$("#activeId").val();
					var id=$("#id").val();
					$.post("checkGroupName",{proviceId:proviceId,cityId:cityId,name:name,activeId:activeId,id:id},function(data){
						if(data=='1'){
							alert("此城市可能有同名的组！"); 
							return false;
						}else{
							loading('正在提交，请稍等...');
							form.submit();
						}
					})
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$('#btnRebuildQrCodeImg').click(function(){
				var data={
						id:$('#id').val(),
						type:$('#type').val()
				}
				$.post('${ctx}/app/mmsGroup/rebuildQrCodeImg',data,function(data){
					location = "${ctx}/app/mmsGroup/list";
				});
			});
			
		});
		
		function getMmsProvin(proviceId) {
			var proviceId = proviceId.value;
			$("#cityId").empty();
			$("#cityId").select2("val", "");
		 	$.post('getCityListByPriviceId' ,{proviceId:proviceId},function(data){
            $("#cityId").html("<option value=\"\">请选择</option>");
            $(data).each(function(index,dom){
                var children = "<option value="+dom['id']+">"+dom["city"]+"</option>";
                $("#cityId").append(children);
			 			});
		},'json')
		}
		
		
		
		function removedleader(leaderid) {
				var tr = document.getElementById("leder_"+leaderid);
			    tr.parentNode.removeChild(tr);
			    $.ajax({
			    	   type: "POST",
			    	   url: "${ctx}/app/mmsGroup/deleteGroupUser",
			    	   data: {'userId':leaderid}
			    	   });
	    }
	    function removedmember(memberid) {
	    	 $.ajax({
		    	   type: "POST",
		    	   url: "${ctx}/app/mmsGroup/deleteGroupUser",
		    	   data: {'userId':memberid}
		    	   });
				var tr = document.getElementById("member_"+memberid);
			    tr.parentNode.removeChild(tr);
	    }
	    function removedqrcode(qrcodeid) {
	    	 $.ajax({
		    	   type: "POST",
		    	   url: "${ctx}/app/mmsGroup/deleteQrcode",
		    	   data: {'qrcodeId':qrcodeid}
		    	   });
				var tr = document.getElementById("qrcode_"+qrcodeid);
			    tr.parentNode.removeChild(tr);
			   
	    }

		
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/app/mmsGroup/list">组列表</a></li>
		<li class="active"><a href="${ctx}/app/mmsGroup/form">组${not empty mmsActivity.id?'修改':'添加'}</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="mmsGroup" action="${ctx}/app/mmsGroup/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">组名称</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="50" class="required"/>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">省份</label>
			<div class="controls"> 
				<form:select path="proviceId" class="input-medium required" onchange="getMmsProvin(this)">
					<option value="">--请选择--</option>
					<form:options items="${proviceList}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
				<form:select path="cityId" class="input-medium required">
					<!-- <option value="">--请选择--</option> -->
					<form:options items="${cityList}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">组详细地址</label>
			<div class="controls">
				<form:input path="detailAddress" htmlEscape="false" maxlength="50" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">活动名称</label>
			<div class="controls">
				<form:select path="activeId" class="input-medium required">
					<form:options items="${activityList}" itemLabel="activityName" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<c:if test="${flag=='1'&&sflag=='1' }">
		<div class="control-group">
			<label class="control-label">组长<br/></label>
			<div class="controls">
				<table id="uerLeader" class="table table-striped table-bordered table-condensed">
					<thead><tr><th class="sort-column name">用户名</th><th class="sort-column name">组长名称</th><th>成员手机号</th><!-- <th>操作</th> --></tr></thead>
					<tbody id="uersss">
					<c:forEach items="${userLeaderList}" var="uerLeader">
						<tr id="leder_${uerLeader.id}">
							<td hidden="uerLeader.id" width="20">${uerLeader.id}</td>
							<td>${uerLeader.loginName}</td>
							<td>${uerLeader.name}</td>
							<td>${uerLeader.mobile}</td>
							<%-- <td>
			    				<button id="userId" onclick="removedleader(${uerLeader.id})">移除</button>
							</td> --%>
						</tr>
					</c:forEach>
					</tbody>
				</table>
			</div>
		</div> 
		<div class="control-group">
			<label class="control-label">组成员</label>
			<div class="controls">
				<table id="uerMember" class="table table-striped table-bordered table-condensed">
					<thead><tr><th class="sort-column name">用户名</th><th class="sort-column name">成员名称</th><th>成员手机号</th><!-- <th>操作</th> --></tr></thead>
					<tbody>
					<c:forEach items="${userMemberList}" var="uerMember">
						<tr id="member_${uerMember.id}">
							<td hidden="uerMember.id">${uerMember.id}</td>
							<td>${uerMember.loginName}</td>
							<td>${uerMember.name}</td>
							<td>${uerMember.mobile}</td>
							<%-- <td>
			    				<button id="memberId" onclick="removedmember(${uerMember.id})">移除</button>
							</td> --%>
						</tr>
					</c:forEach>
					</tbody>
				</table>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">二维码</label>
			<div class="controls">
				<table id="qrcode" class="table table-striped table-bordered table-condensed">
					<thead><tr><th class="sort-column name">二维码号段</th><th class="sort-column name">二维码编号</th><th class="sort-column name">活动名称</th><th>二维码类型</th></tr></thead>
					<tbody>
					<c:forEach items="${qrcodeList}" var="qrcode">
						<tr id="qrcode_${qrcode.id}">
							<td>${qrcode.qrcodeNo}</td>
							<td>${qrcode.qrcodeNum}</td>
							<td><%-- ${qrcode.mmsActivity.activityName} --%>
							<c:forEach items="${activityList}" var="activity">
							<c:choose>
								<c:when test="${activity.id==qrcode.activityId}">
									${activity.activityName}
								</c:when>
							</c:choose>
						</c:forEach></td>
							<td>
								<c:if test="${not empty qrcode.qrcodeType}">
									<c:choose>
									<c:when test="${qrcode.qrcodeType eq '0'}">书</c:when>
									<c:when test="${qrcode.qrcodeType eq '1'}">宣传单页</c:when>
									<c:otherwise>海报/易拉宝</c:otherwise>
									</c:choose>
								</c:if>
							</td>
						</tr>
					</c:forEach>
					</tbody>
				</table>
			</div>
		</div>
		</c:if>
		<c:if test="${sflag=='0' }">
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>		
		</div>
		</c:if>
	</form:form>
</body>
</html>